package cn.dnui_zll731.dnuifood_731zlll.Adapter;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
import cn.dnui_zll731.dnuifood_731zlll.common.Constants;
import cn.dnui_zll731.dnuifood_731zlll.R;
import cn.dnui_zll731.dnuifood_731zlll.bean.FoodBean;
import cn.dnui_zll731.dnuifood_731zlll.controller.FoodInfoActivity;
public class FoodListAdapter extends RecyclerViewAdapter<FoodListAdapter.ViewHolder> {
    private String phonenum,shopname;
    public FoodListAdapter(Context context, List data, int layoutResource,String phonenum,String shopname) {
        super(context, data, layoutResource);
        this.phonenum=phonenum;
        this.shopname=shopname;
    }

    @Override
    public void onBindViewHolder(FoodListAdapter.ViewHolder holder, int position) {
        //负责将每个子项holder绑定数据。俩参数分别是RecyclerView.ViewHolder holder, int position；
//      final ShopBean entity = data.get(position);
        final FoodBean foodBean = (FoodBean) data.get(position);
        if (foodBean == null)
            return;

        ViewHolder viewHolder = (ViewHolder) holder;

        if (!foodBean.getPic().equals(""))
            Picasso.with(context).load(Constants.BASE_URL+foodBean.getPic()).into(viewHolder.food_pic);
        viewHolder.food_foodname.setText(foodBean.getFoodname());
        viewHolder.food_price.setText(foodBean.getPrice()+"元");
        viewHolder.food_intro.setText("简介:"+foodBean.getIntro());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到店铺页面
                Intent intent = new Intent(context,FoodInfoActivity.class);
                intent.putExtra("food_id",foodBean.getFood_id());
                intent.putExtra("phonenum",phonenum);
                intent.putExtra("shop_name",shopname);
                context.startActivity(intent);
            }
        });
    }


    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView food_pic;
        TextView food_foodname,food_price,food_intro;

        public ViewHolder(View itemView) {
            super(itemView);
            food_pic = itemView.findViewById(R.id.food_pic);
            food_foodname = itemView.findViewById(R.id.food_foodname);
            food_price = itemView.findViewById(R.id.food_price);
            food_intro = itemView.findViewById(R.id.food_intro);
        }
    }
}
